/*
 * @Author: t-xiangqun.li t-xiangqun.li@pcitc.com
 * @Date: 2025-10-22 14:32:20
 * @LastEditors: t-xiangqun.li t-xiangqun.li@pcitc.com
 * @LastEditTime: 2025-10-22 19:01:57
 * @FilePath: \electrconVue\src\db.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Dexie, { EntityTable } from "dexie";
import { ProviderProps, ConversationProps, MessageProps } from "./types";
import { providerList } from "./utils/mockData";

export const db = new Dexie("vChatDatabase") as Dexie & {
  providers: EntityTable<ProviderProps, "id">; // 表的名称: providers, id主键
  conversations: EntityTable<ConversationProps, "id">;
  messages: EntityTable<MessageProps, "id">;
};

db.version(1).stores({
  providers: "++id, name",
  conversations: "++id, providerId",
  messages: "++id, conversationId",
});

export const initProviders = async () => {
  const count = await db.providers.count();
  if (count === 0) {
    db.providers.bulkAdd(providerList);
  }
};
